import React, { Component } from 'react'
import './4.css';
export default class DivShow extends Component {
  //1. 声明状态 
  state = {
    opacity: 1
  }

  render() {
    return (
      <div>
        <button onClick={this.switch}>点击显示与隐藏</button>
        {/* 2. 使用状态 */}
        <div  className='box' style={{opacity: this.state.opacity}}></div>
      </div>
    )
  }

  // 3. 绑定事件
  switch = () => {
    this.setState({
      opacity: this.state.opacity ? 0 : 1
    })
  }
}
